package br.ucb.bean;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

@Entity
@Table(name = "turma")
public class Turma implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7904303032313871240L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "idTurma")
	private Integer codigo;

	@Enumerated(EnumType.STRING)
	@Column(name = "turno")
	private EnumTurnos turno;

	@Column(name = "sala")
	private String sala;
	
	@Column(name = "senha")
	private String senha;

	@OneToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "Disciplina_idDisciplina")
	private Disciplina disciplina;

	@ManyToMany
	@JoinTable(name = "Turma_has_Aluno", joinColumns = @JoinColumn(name = "Turma_idTurma"), inverseJoinColumns = @JoinColumn(name = "Aluno_idAluno"))
	private Collection<Aluno> alunos;

	public Turma() {
		super();
	}

	public Turma(Integer codigo, EnumTurnos turno, String sala,
			Disciplina disciplina) {
		super();
		this.codigo = codigo;
		this.turno = turno;
		this.sala = sala;
		this.disciplina = disciplina;
	}

	public EnumTurnos getTurno() {
		return turno;
	}

	public void setTurno(EnumTurnos turno) {
		this.turno = turno;
	}

	public String getSala() {
		return sala;
	}

	public void setSala(String sala) {
		this.sala = sala;
	}

	public Turma(EnumTurnos turno, String sala) {
		super();
		this.turno = turno;
		this.sala = sala;
	}

	public Integer getCodigo() {
		return codigo;
	}

	public void setCodigo(Integer codigo) {
		this.codigo = codigo;
	}

	public Disciplina getDisciplina() {
		return disciplina;
	}

	public Collection<Aluno> getAlunos() {
		return alunos;
	}

	public void setAlunos(Collection<Aluno> alunos) {
		this.alunos = alunos;
	}

	public void setDisciplina(Disciplina disciplina) {
		this.disciplina = disciplina;
	}
	
	

	public String getSenha() {
		return senha;
	}

	public void setSenha(String senha) {
		this.senha = senha;
	}

	

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((codigo == null) ? 0 : codigo.hashCode());
		result = prime * result + ((sala == null) ? 0 : sala.hashCode());
		result = prime * result + ((senha == null) ? 0 : senha.hashCode());
		result = prime * result + ((turno == null) ? 0 : turno.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Turma other = (Turma) obj;
		if (codigo == null) {
			if (other.codigo != null)
				return false;
		} else if (!codigo.equals(other.codigo))
			return false;
		if (sala == null) {
			if (other.sala != null)
				return false;
		} else if (!sala.equals(other.sala))
			return false;
		if (senha == null) {
			if (other.senha != null)
				return false;
		} else if (!senha.equals(other.senha))
			return false;
		if (turno != other.turno)
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Turma [codigo=" + codigo + ", turno=" + turno + ", sala="
				+ sala + "]";
	}

}
